/**
 * Copyright &copy; com.smooth.common
 */
package com.smooth.site.sx.mag.basedata.province.service;

import java.util.Date;
import java.util.List;

import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.smooth.common.site.common.enums.DelFlagEnums;
import com.smooth.common.site.common.persistence.Page;
import com.smooth.common.site.common.utils.IdGenerater;
import com.smooth.dao.gen.BaseProvincesMapper;
import com.smooth.dao.gen.bean.BaseProvinces;
import com.smooth.dao.gen.bean.BaseProvincesExample;

/**
 * 省份Service
 * @author 北冥
 * @version 2019-02-05
 */
@Service
@Transactional(readOnly = true)
public class BaseProvincesService{
	Logger log = LoggerFactory.getLogger(BaseProvincesService.class);
	@Autowired
	BaseProvincesMapper baseProvincesMapper;
	@Autowired
	IdGenerater idGenerater;
	
	public BaseProvinces get(String no) {
		return baseProvincesMapper.selectByPrimaryKey(no);
	}
	
	public List<BaseProvinces> findList(BaseProvinces baseProvinces) {
		BaseProvincesExample baseProvincesExample = new BaseProvincesExample();
		BaseProvincesExample.Criteria criteria = baseProvincesExample.createCriteria();
		
		return baseProvincesMapper.selectByExample(baseProvincesExample);
	}
	
	public Page<BaseProvinces> findPage(Page<BaseProvinces> page, BaseProvinces baseProvinces) {
		BaseProvincesExample baseProvincesExample = new BaseProvincesExample();
		BaseProvincesExample.Criteria criteria = baseProvincesExample.createCriteria();
		
		baseProvincesExample.setPage(page);
		
		List<BaseProvinces> dlist = baseProvincesMapper.selectByExample(baseProvincesExample);
		page.setList(dlist);
		page.setCount(baseProvincesMapper.countByExample(baseProvincesExample));
		
		return page;
	}
	
	@Transactional(readOnly = false)
	public void save(BaseProvinces baseProvinces) {
		if(StringUtils.isNotEmpty(baseProvinces.getId())&&get(baseProvinces.getId())!=null) {
			int optNum = baseProvincesMapper.updateByPrimaryKeySelective(baseProvinces);
			if(optNum==1) {
				log.info("更新 student 数据【"+baseProvinces.toString()+"】成功");
			}else {
				log.error("更新 student 数据【"+baseProvinces.toString()+"】失败");
			}
		}else {
			Date date = new Date();
			baseProvinces.setCreateDate(date);
			baseProvinces.setId(idGenerater.genClsNo("baseProvinces"));
			baseProvinces.setUpdateDate(date);
			int optNum =  baseProvincesMapper.insertSelective(baseProvinces);
			if(optNum==1) {
				log.info("插入 student 数据【"+baseProvinces.toString()+"】成功");
			}else {
				log.error("插入 student 数据【"+baseProvinces.toString()+"】失败");
			}
		}
	}
	
	@Transactional(readOnly = false)
	public void delete(BaseProvinces baseProvinces) {
		baseProvincesMapper.deleteByPrimaryKey(baseProvinces.getId());
	}
	
}